package com.football.helper;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.HibernateException;
import org.springframework.beans.factory.annotation.Autowired;

import com.football.model.League;
import com.football.model.Team;
import com.football.service.Interface.LeagueService;
import com.football.service.Interface.TeamService;

public class SchedulerJob {

	@Autowired
	private TeamService teamService;

	@Autowired
	private LeagueService leagueService;

	public void schedulerJob() {
		try {
			System.out.println("Start scheduler");

			League l = new League();
			l.setId(1);
			l.setName("English Primer League");
			leagueService.addNewLeague(l);

			System.out.println("add new league");

			List<League> lt = new ArrayList<League>();
			lt.add(l);

			Team t = new Team();
			t.setId(1);
			t.setName("Liverpool");
			t.setLeagues(lt);

			teamService.addNewTeam(t);

			// l.setTeams(lt);

		} catch (HibernateException hb) {
			System.out.println("cause: " + hb.getCause());
			System.out.println("message: " + hb.getMessage());
		} catch (Exception e) {
			System.out.println(e.getStackTrace());
		}

		System.out.println("end scheduler");
	}
}
